[client] Fix IPv6 address formatting in DNS address construction#5603
[client] Fix IPv6 address formatting in DNS address construction#5603lixmal merged 1 commit intonetbirdio:mainfrom
Conversation
Replace fmt.Sprintf("%s:%d", ip, port) with net.JoinHostPort() to
properly handle IPv6 addresses that need bracket wrapping (e.g.,
[2606:4700:4700::1111]:53 instead of 2606:4700:4700::1111:53).
Without this fix, configuring IPv6 nameservers causes "too many colons
in address" errors because Go's net.Dial cannot parse the malformed
address string.
Fixes netbirdio#5601
Related to netbirdio#4074
Co-Authored-By: Claude (claude-opus-4-6) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR fixes IPv6 address formatting in DNS address construction by replacing Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Tip CodeRabbit can generate a title for your PR based on the changes.Add |
|
|
easonysliu seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
|
Can you please stick to the PR template? |



Summary
Fixes #5601
Related to #4074
Several places in the DNS client code construct server addresses using
fmt.Sprintf("%s:%d", ip, port). This produces malformed addresses when the IP is IPv6, since IPv6 addresses contain colons and need brackets when combined with a port (e.g.,[2606:4700:4700::1111]:53instead of2606:4700:4700::1111:53).This causes DNS resolution to fail with
dial udp: address 2606:4700:4700::1111:53: too many colons in addresswhen IPv6 nameservers are configured.Changes
Replaced
fmt.Sprintf("%s:%d", ip, port)withnet.JoinHostPort()in:client/internal/routemanager/dnsinterceptor/handler.go— upstream DNS address for the DNS interceptor (most critical, directly causes query failures)client/internal/dns/service_listener.go— DNS listener address and port binding probesclient/internal/routemanager/client/client.go— DNS address for dynamic route handlersnet.JoinHostPort()is the standard Go idiom for this — it automatically wraps IPv6 addresses in brackets. The rest of the codebase already uses this function in many places (e.g.,peer/worker_ice.go,ssh/detection/detection.go).Test plan
go test ./client/internal/dns/...)go test ./client/internal/routemanager/...)2606:4700:4700::1111) and verify DNS queries succeedSummary by CodeRabbit